const BlogDao = require('../dao/blog-dao')
const BaseServices = require('./base-service')

class BlogServices extends BaseServices{
    constructor(dao = new BlogDao()) {
        super();
        this.dao = dao
    }
    delete(id) {
        super.delete(id);
    }

    /**
     * 获取文章列表
     * @param pageIndex
     * @param pageSize
     * @param options
     * @returns {*}
     */
    async getArticlesList (pageIndex = 1,pageSize = 20,options = {}){
        const {category} = options
        // const RowDataPacket = await this.dao.getCategoryIdByName(category)
        // console.log("RowDataPacket:",RowDataPacket)
        // options.categoryId = RowDataPacket[0].id
        const values = await this.dao.getArticlesList(pageIndex,pageSize,options)
        return values
    }

    /**
     * 新增一篇文章
     * @param article
     * @param callbacl
     * @returns {{}|*}
     */
    insertOneArticle(article){
        return this.dao.insertOneArticle(article)
    }

    /**
     * 更新文章
     * @param article
     * @returns {{}}
     */
    async updateOneArticle(article){
        const OkPacket = await this.dao.updateOneArticle(article)
        console.log("services=============OkPacket:",OkPacket)
        return OkPacket
    }

    /**
     * 获取一篇文章
     * @param id
     * @returns {Promise<{}>}
     */
    async getArticleById(id) {
        const RowDataPacket = await this.dao.getArticleById(id)
        return RowDataPacket
    }

    /**
     * 删除一篇文章
     * @param id
     * @returns {{}}
     */
    async deleteArticleById(id) {
        const OkPacket = await dao.deleteArticleById(id)
        return OkPacket
    }

    /**
     * 获取文章类型
     * @returns {*}
     */
    queryCategoryList(){
        return this.dao.queryCategoryList()
    }
}

module.exports = BlogServices;
